<?php

/**
 * 地址主控类
 */

namespace Manager\Controller;


use Manager\Model\AddrModel;

class AddrController extends ManagerController
{

    private $_M;

    public function __construct()
    {
        parent::__construct();
        $this->_M = new AddrModel();

    }



    public function listAddr()
    {

        $listInfo= $this->_M->getAddrList();
        $this->assign("listInfo",$listInfo);
        $this->display();
    }


    public function addAddr()
    {
        if (IS_POST) {
            $data = $this->_M->create();
            dump($data);
            exit;
            if ($this->_M->add($data)) {
                $this->success('添加成功', 'listAddr');
            } else {
                $this->error('添加失败!稍后再试', 'listAddr');
            }
        } else {
            $this->display();
        }
    }


    public function modifyAddr()
    {
        if (IS_POST) {

            $dbData = $this->_M->create();
            if(empty($dbData['status'])){
                $dbData['status']=0;
            }
            if ($this->_M->save($dbData)) {
//                $this->success('修改成功', 'listAddr');
                $this->redirect('Addr/listAddr');
            } else {
                $this->error("修改失败", "Addr/listAddr", 3);
            }
        } else {
            $id = $_GET['id'];
            $confInfo=$this->_M->getAddrInfoById($id);
            $this->assign("conf",$confInfo);
            $this->display();
        }


    }

    public function disableAddr()
    {
        if (IS_GET) {
            $id = $_GET['id'];
            $this->_M->status = 0;

            if ($this->_M->where("id=$id")->save()) {

            }
        } else {

        }

    }

    public function ableAddr()
    {
        if (IS_GET) {
            $id = $_GET['id'];
            $this->_M->status = 0;

            if ($this->_M->where("id=$id")->save()) {

            }
        } else {

        }
    }
}